package com.ruoyi.eam.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamAsset;
import com.ruoyi.eam.doman.SummaryAsset;
import com.ruoyi.eam.doman.vo.EamAssetVo;
import com.ruoyi.eam.service.IEamAssetService;
import com.ruoyi.eam.service.SummaryStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 固定资产Controller
 *
 * @author ruoyi
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/asset")
public class EamAssetController extends BaseController
{
    @Autowired
    private IEamAssetService eamAssetService;
    @Autowired
    private SummaryStatusService summaryStatusService;


    /**
     * 查询固定资产列表
     */
    //@RequiresPermissions 这个注解用于指定一个方法或类需要某个特定的权限才能被访问。
    //@RequiresPermissions("system:asset:list")
    @GetMapping("/list")
    public TableDataInfo list(EamAsset eamAsset)
    {
        startPage();
        List<EamAsset> list = eamAssetService.selectEamAssetByuseStatus(eamAsset);
        return getDataTable(list);
    }



    @GetMapping("/lists")
    public TableDataInfo lists(EamAsset eamAsset)
    {
        startPage();
        List<EamAsset> list = eamAssetService.selectEamAssetList(eamAsset);
        return getDataTable(list);
    }

    @GetMapping("/queryEamDateList")
    public TableDataInfo queryEamDateList(EamAsset eamAsset)
    {
        startPage();
        List<EamAsset> list = eamAssetService.queryEamDateList(eamAsset);
        return getDataTable(list);
    }


    @GetMapping("/getListAll")
    public TableDataInfo getListAll(EamAsset eamAsset)
    {
        startPage();
        List<EamAsset> list = eamAssetService.getListAll(eamAsset);
        return getDataTable(list);
    }

    @GetMapping(value = "/getUseStatus/{useStatus}")
    public AjaxResult getUseStatus(@PathVariable("useStatus") Long useStatus)
    {
        return success(eamAssetService.selectEamAssetUseStatus(useStatus));
    }

    @GetMapping(value = "/getCounts")
    public AjaxResult getCounts()
    {
        return success(eamAssetService.selectEamAssetCounts());
    }

    @GetMapping(value = "/getPriceSum")
    public AjaxResult getPriceSum()
    {
        return success(eamAssetService.selectEamAssetPriceSum());
    }

    @GetMapping("/count")
    public AjaxResult count()
    {
        return AjaxResult.success(eamAssetService.selectEamAssetCount());
    }

    /**
     * 导出固定资产列表
     */
//    @RequiresPermissions("system:asset:export")
    @Log(title = "固定资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamAsset eamAsset)
    {
        List<EamAsset> list = eamAssetService.selectEamAssetList(eamAsset);
        ExcelUtil<EamAsset> util = new ExcelUtil<EamAsset>(EamAsset.class);
        util.exportExcel(response, list, "固定资产数据");
    }

    /**
     * 获取固定资产详细信息
     */
    //@RequiresPermissions("system:asset:query")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return success(eamAssetService.selectEamAssetByAssetId(assetId));
    }

    /**
     * 新增固定资产
     */
    //@RequiresPermissions("system:asset:add")
    @Log(title = "固定资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamAsset eamAsset)
    {
        return toAjax(eamAssetService.insertEamAsset(eamAsset));
    }

    /**
     * 修改固定资产
     */
    //@RequiresPermissions("system:asset:edit")
    @Log(title = "固定资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamAsset eamAsset)
    {
        return toAjax(eamAssetService.updateEamAsset(eamAsset));
    }

    /**
     * 删除固定资产
     */
    //@RequiresPermissions("system:asset:remove")
    @Log(title = "固定资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds)
    {
        return toAjax(eamAssetService.deleteEamAssetByAssetIds(assetIds));
    }

    /*查询待审核的单号汇总*/
    @GetMapping("/summarylist")
    public TableDataInfo summarylist()
    {
        startPage();
        List<SummaryAsset> list = summaryStatusService.querySummaryStatus();
        return getDataTable(list);
    }

    /*查询待审核的单号汇总*/
    @GetMapping("/assetTypeList")
    public Map<String,Object> assetTypeList()
    {
        Map<String,Object> rm = new HashMap<>();
        rm.put("statusCount1",eamAssetService.queryTypeList(4L));
        rm.put("statusCount2",eamAssetService.queryTypeList(100L));
        rm.put("statusCount3",eamAssetService.queryTypeList(101L));
        rm.put("statusCount4",eamAssetService.queryTypeList(103L));
        return rm;
    }
}
